1 00:00:01,090 --> 00:00:02,230 In our wave loop. 2 00:00:02,230 --> 00:00:08,320 Let's do some zombie counting and only spawn zombies when we clear a group. 3 00:00:08,350 --> 00:00:10,010 All right, so how do we do that? 4 00:00:10,030 --> 00:00:11,600 Let's go to workspace. 5 00:00:11,620 --> 00:00:12,940 Hit the plus. 6 00:00:12,940 --> 00:00:14,320 Add a folder. 7 00:00:14,350 --> 00:00:17,410 I'm going to call this folder Zombies. 8 00:00:18,430 --> 00:00:23,200 And what I'm going to do is I'm going to spawn the zombie in that folder, and then I can count the 9 00:00:23,200 --> 00:00:25,500 number of zombies in the folder quite easily. 10 00:00:25,510 --> 00:00:28,470 So we're going to go over to our session utils. 11 00:00:28,480 --> 00:00:34,090 Now I have it here, but if you don't have it, go down to server script service, open it up and you 12 00:00:34,090 --> 00:00:35,740 have your session utils. 13 00:00:35,770 --> 00:00:41,920 Notice that when we do spawn zombies, the parent of the zombie is the workspace. 14 00:00:41,920 --> 00:00:44,260 We need to change that to the folder. 15 00:00:44,410 --> 00:00:47,350 I'm actually going to make a variable for that up top though. 16 00:00:47,350 --> 00:00:55,060 I'm going to say local zombie folder workspace dot zombies. 17 00:00:55,390 --> 00:00:56,380 So we want to change it. 18 00:00:56,380 --> 00:00:58,240 It's easy to find up at the top. 19 00:00:58,630 --> 00:00:59,380 All right. 20 00:00:59,380 --> 00:01:01,510 You can even call that like, monster folder. 21 00:01:02,230 --> 00:01:05,140 Now I'll say zombie folder down here. 22 00:01:05,680 --> 00:01:09,220 Now, when we spawn a zombie, it's going to go in that folder. 23 00:01:09,230 --> 00:01:11,950 It's not going to be spread out all through the workspace. 24 00:01:12,190 --> 00:01:16,930 So now I need to go to my wave loop where I call spawn zombies. 25 00:01:16,930 --> 00:01:22,360 And if you don't have your wav loop, it's down here in server script service, just double click wave 26 00:01:22,360 --> 00:01:22,900 loop. 27 00:01:23,170 --> 00:01:23,970 Cool. 28 00:01:23,980 --> 00:01:26,770 Let's get a reference to our folder. 29 00:01:26,770 --> 00:01:29,010 So a variable for the folder. 30 00:01:29,020 --> 00:01:31,180 Call that zombie folder again. 31 00:01:31,900 --> 00:01:33,460 So don't get confused. 32 00:01:33,460 --> 00:01:36,220 Workspace Zombies. 33 00:01:36,700 --> 00:01:43,930 Now down here where we do our spawning zombies, let's count the number of elements in that folder and 34 00:01:43,930 --> 00:01:45,910 only course bond zombies. 35 00:01:46,270 --> 00:01:47,470 If there's zero. 36 00:01:47,470 --> 00:01:49,720 If it's zero, no zombies left. 37 00:01:49,870 --> 00:01:55,480 I'm going to make a variable called C and short for count with no vowels in it. 38 00:01:55,480 --> 00:02:00,580 C int equals zombie folder Get children. 39 00:02:00,580 --> 00:02:03,280 So I'm going to call the zombie folder variable. 40 00:02:03,370 --> 00:02:08,680 I'm going to do this method called Get Children, which gets everything in the zombie folder, but that's 41 00:02:08,680 --> 00:02:09,820 only zombies. 42 00:02:09,940 --> 00:02:15,430 And then in the front I'm going to say we'll put that a pound sign there. 43 00:02:15,460 --> 00:02:17,890 That's going to get me the number. 44 00:02:18,630 --> 00:02:23,160 That is in this table that was produced by the Get children. 45 00:02:23,160 --> 00:02:24,930 So we're going to get the number of zombies. 46 00:02:24,960 --> 00:02:25,950 Long story short. 47 00:02:25,950 --> 00:02:26,400 Right. 48 00:02:26,440 --> 00:02:28,380 Number of zombies in that folder. 49 00:02:28,380 --> 00:02:32,160 So if count equals equals zero, then. 50 00:02:33,000 --> 00:02:35,670 Will call spawn zombies. 51 00:02:36,480 --> 00:02:37,500 Cool. 52 00:02:38,040 --> 00:02:39,120 All right, So. 53 00:02:40,100 --> 00:02:42,250 I think we got everything we need here. 54 00:02:42,260 --> 00:02:44,960 Let's just produce more zombies. 55 00:02:45,140 --> 00:02:49,400 Let's say ten, and then I'm going to go to my game. 56 00:02:49,400 --> 00:02:52,940 I'm going to play here so I don't have to run up there. 57 00:02:52,940 --> 00:02:54,140 It says Play here. 58 00:02:54,170 --> 00:02:55,190 That's good. 59 00:02:55,840 --> 00:02:57,150 Let's count our zombies. 60 00:02:57,150 --> 00:03:00,860 So I'm going to open up our workspace. 61 00:03:00,880 --> 00:03:02,800 This is my zombie folder. 62 00:03:04,270 --> 00:03:05,030 Here we go. 63 00:03:05,050 --> 00:03:06,250 Getting zombies. 64 00:03:07,300 --> 00:03:09,280 See how they're stacking, though? 65 00:03:09,310 --> 00:03:10,800 We're not giving enough. 66 00:03:10,810 --> 00:03:13,420 Enough spawn locations for the number. 67 00:03:14,140 --> 00:03:19,880 All right, so a couple of zombies died, and now we should stop creating new zombies. 68 00:03:19,900 --> 00:03:20,800 There are some might. 69 00:03:20,800 --> 00:03:24,550 Some might disappear, but we limited it.